package com.fulu.game.bi.controller.auth;

import com.fulu.game.bi.common.controller.BaseController;
import com.fulu.game.bi.entity.po.auth.BiPermission;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.auth.permission.PermissionQueryVO;
import com.fulu.game.bi.entity.vo.auth.permission.PermissionSaveVO;
import com.fulu.game.bi.redis.service.auth.BiPermissionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 菜单管理||路由管理||权限管理
 */
@RestController
@RequestMapping("/api/v1/permission")
@Slf4j
public class PermissionController extends BaseController {

    @Autowired
    private BiPermissionService biPermissionService;
    /**
     * 查询列表
     */
    @PostMapping("/list-all")
    public Result<List<BiPermission>> list(Integer userId) {
        List<BiPermission> page = biPermissionService.listAll(userId);
        return Result.success().data(page).msg("查询成功");
    }


    /**
     * 查询列表
     */
    @PostMapping("/list")
    public Result<Page<BiPermission>> list(@Valid PermissionQueryVO vo) {
        PageInfo<BiPermission> page = biPermissionService.list(vo);
        return Result.success().data(page).msg("查询成功");
    }

    /**
     * 新增路由
     */
    @PostMapping("/save")
    public Result<BiPermission> save(PermissionSaveVO vo) {
        BiPermission permission = biPermissionService.save(vo);

        return Result.success().data(permission).msg("保存成功");
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/query")
    public Result sysRouterQuery(@RequestParam("id") Integer id) {
        BiPermission sysRouter = biPermissionService.findById(id);
        return Result.success().data(sysRouter).msg("查询成功");
    }

    /**
     * 根据id删除
     */
    @PostMapping("/del")
    public Result sysRouterDelete(@RequestParam("id") Integer id) {
        biPermissionService.deleteById(id);
        return Result.success().msg("删除成功");
    }
}
